#!/usr/bin/env python
# @coding  : utf-8
# @File    : t04.py
# @Time    : 2022/3/26 16:07
# @Author  : xdd
# @Software: PyCharm
# @desc :$


import math
from numpy import log2

# print("Log value for base 2: ")
#
# print(-3/8 * math.log2(3/8))
# print(5/8 * math.log2(5/8))
# print(-3/8 * math.log2(3/8)-5/8 * math.log2(5/8))
# print(math.log2(1/3) )
# print(- 1/3 * math.log2(1/3) - 2/3 * math.log2(2/3))
# ================32支球队获胜概率相同求信息熵=========================

# ans=0;
# for i in range(1,33):
#     ans += (1/32)*log2(1/32)
#     print("[MYOUT]  i:  "+str(i))
# ans*=-1;
# print(ans)
# =================所以信息熵为5=======================


# ==================7000个汉字的信息熵=======================
# ans=0;
# for i in range(1,7001):
#     ans += (1/7000)*log2(1/7000)
# ans*=-1;
# print(ans)#12.773139206718408

# ==================两人下棋一人的胜率为0.8=======================
# ans=0;
# ans += (8/10)*log2(8/10)+(2/10)*log2(2/10)
# ans*=-1;
# print(ans)#0.7219280948873623

# ==================8部电影看了六部=======================
# ans=0;
# list=[6,2]  #描述有多少种数据，及其值
# count=0;
# for i in range(len(list)): #计算总数
#     count+=list[i];
#
# for i in range(len(list)):
#     p = list[i]/count
#     ans+=p*log2(p)
#
# ans*=-1;
# print(ans)#0.8112781244591328

# ==================8部电影看了六部 考虑类型=======================
# ans=0;
# list=[[3,0],[1,1],[2,1]]  #描述有多少种数据，及其值
# listarry=[] #存储每种类型和观看的计算值
# count=0;
# countarry=[] #保存每种类型的数量
# for item in list: #计算总数
#
#     countS=item[0]+item[1]#两点数据型， 计算数据和
#     count += countS;
#     anss=0
#     for i in (0,1):
#         p=item[i]/countS
#         if(p==1):  #如果为1就是全概率实践
#             break;
#         print("[MYOUT]  p:  "+str(p))
#         anss+=p*log2(p)
#         print("[MYOUT]  anss:  "+str(anss))
#     anss*=-1;
#     listarry.append(anss)
#     countarry.append(countS)
#
# print("[MYOUT]  listS:  "+str(listarry))
# print("[MYOUT]  count:  "+str(countarry))
# print("[MYOUT]  count:  "+str(count))
# for item in range(len(listarry)):
#     ans+=(countarry[item]/count)*(listarry[item])
# print(ans)#0.5943609377704335


# ==================8部电影看了六部 考虑类型=======================
# ans=0;
# list=[[1,0],[3,0],[2,1],[0,1]]  #描述有多少种数据，及其值
# listarry=[] #存储每种类型和观看的计算值
# count=0;
# countarry=[] #保存每种类型的数量
# for item in list: #计算总数
#
#     countS=item[0]+item[1]#两点数据型， 计算数据和
#     count += countS;
#     anss=0
#
#     for i in (0,1):
#         p=item[i]/countS
#         if(p==1 or p==0):  #如果为1就是全概率实践
#             anss=0;
#             break;
#         print("[MYOUT]  p:  "+str(p))
#         anss+=p*log2(p)
#         print("[MYOUT]  anss:  "+str(anss))
#     anss*=-1;
#     listarry.append(anss)
#     countarry.append(countS)
#
# print("[MYOUT]  listS:  "+str(listarry))
# print("[MYOUT]  count:  "+str(countarry))
# print("[MYOUT]  count:  "+str(count))
# for item in range(len(listarry)):
#     ans+=(countarry[item]/count)*(listarry[item])
# print(ans)#0.3443609377704336
# ===================抽取小球实验======================
# 有顺序的返回，抽到固定顺序颜色小球的概率
#l,l,l,r 计算他们我的熵值
    # ==================固定顺序颜色小球的视角=======================

# list=[]
# ans =0
# for i in range(0,3):
#     p = 3/4;
#     ans+=log2(p)
# ans+=log2(1/4)
# print(ans) #-3.2451124978365313 再乘以-1/4 就类似下面的计算
    # =================计算信息熵========================
# ans=0;
# list=[3,1]  #描述有多少种数据，及其值
# count=0;
# for i in range(len(list)): #计算总数
#     count+=list[i];
#
# for i in range(len(list)):
#     p = list[i]/count
#     ans+=p*log2(p)
#
# ans*=-1;
# print(ans)#0.8112781244591328
